package com.bwsoft.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.log4j.Logger;
import org.springframework.stereotype.Service;

import com.bwsoft.domain.DictionaryData;
import com.bwsoft.service.DictionaryDataService;

@Service(DictionaryDataService.NAME)
public class DictionaryDataServiceImpl extends BaseServiceImpl implements DictionaryDataService {

	private static Logger LOG = Logger.getLogger(DictionaryDataServiceImpl.class);

	/**
	 * 
	 */
	@Override
	public DictionaryData getDictionaryDataByNameValue(String name, String key) {
		DictionaryData dicData = (DictionaryData) dictionaryDataDao.findByHql(
				"from DictionaryData dic where dic.dictionary.dicName='" + name + "' and dic.dicKey='" + key + "'")
				.get(0);
		return dicData;
	}

	@Override
	public String getDicValueDataByNameValue(String name, Integer key) {
		String dicValue="";
		if(key==null){return dicValue;}
		List<DictionaryData> dicDatas =  dictionaryDataDao.findByHql(
				"from DictionaryData dic where dic.dictionary.dicName='" + name + "' and dic.dicKey='" + key + "'");
		
		if(dicDatas.size()==0){return dicValue;}
		return dicDatas.get(0).getDicValue();
	}
	
	@Override
	public String getDicValueDataByNameValue(String name, String key) {
		String dicValue="";
		if(key==null){return dicValue;}
		List<DictionaryData> dicDatas =  dictionaryDataDao.findByHql(
				"from DictionaryData dic where dic.dictionary.dicName='" + name + "' and dic.dicKey='" + key + "'");
		
		if(dicDatas.size()==0){return dicValue;}
		return dicDatas.get(0).getDicValue();
	}
	
	public Map<String, String> getDicDataByName(String name){
		List<DictionaryData> dicDatas =  dictionaryDataDao.findByHql(
				"from DictionaryData dic where dic.dictionary.dicName='" + name+"'" );
		Map<String, String> m=new HashMap<String, String>();
		for (DictionaryData dictionaryData : dicDatas) {
			m.put(dictionaryData.getDicKey(), dictionaryData.getDicValue());
		}
		return m;
	}
}
